package co.chuangdian.oflauncher.wallpapers.setting;

import java.io.File;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import cn.onekit.ASSET;
import cn.onekit.CALLBACK;
import cn.onekit.CONFIG;
import cn.onekit.FSO;
import cn.onekit.JSON;
import cn.onekit.MESSAGE;
import co.chuangdian.oflauncher.R;
import co.chuangdian.oflauncher.folders.setting.AddFolderActivity;

public class Wallpaper_LockScreenFragment extends Fragment {

	private View view;
	JSONObject lockscreen;
	ImageView lockscreen_image;
	FrameLayout fl;

	int number;
	int id_number;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.wallpaper_lockscreen, container, false);

		fl = (FrameLayout) view.findViewById(R.id.fl);
		lockscreen_image = (ImageView) view.findViewById(R.id.lockscreen_image);
		return view;
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		MESSAGE.receive("lockscreen_wallpaper", null, new CALLBACK<Bundle>() {
			@Override
			public void run(boolean isError, Bundle result) {
				loadSetting();
			}
		});

		loadSetting();

		fl.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(getActivity(), LockScreen_Album.class));

			}
		});

	}

	public void loadSetting() {
		// 获取setting中的wallpaper数据
		lockscreen = JSON.parse((String) CONFIG.get("lockscreen"));
		File path = FSO.photos(lockscreen.optString("cover"));
		Bitmap image = FSO.loadImage(path.getPath(), false);
		lockscreen_image.setImageBitmap(image);
	}

}
